//
//  TabBarViewController.m
//  Fruit
//
//  Created by kai xie on 15/8/7.
//  Copyright (c) 2015年 kai xie. All rights reserved.
//

#import "TabBarViewController.h"
#import "NavigationViewController.h"
#import "BluetoothViewController.h"
#import "ShopViewController.h"
#import "MineViewController.h"
@interface TabBarViewController ()

@end

@implementation TabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加tabbar顶部线条
    CALayer *topBorder = [CALayer layer];
    topBorder.frame = CGRectMake(0.0f, 0.0f,kSCREEN_WIDTH, 0.5f);
    topBorder.backgroundColor = [UIColor lightTextColor].CGColor;
    [self.tabBar.layer addSublayer:topBorder];
    
    // 添加子控件
    UIViewController *index = [[BluetoothViewController alloc] init];
    [self addOneChildVc:index title:@"蓝牙" imageName:@"bar_bluetooth" selectedimage:@"bar_bluetooth"];
    
    UIViewController *find = [[ShopViewController alloc] init];
    [self addOneChildVc:find title:@"商店" imageName:@"bar_store" selectedimage:@"bar_store"];
    
    UIViewController *active = [[MineViewController alloc] init];
    [self addOneChildVc:active title:@"我" imageName:@"bar_me" selectedimage:@"bar_me"];
}


- (void)addOneChildVc:(UIViewController *)childVc title:(NSString *)title imageName:(NSString *)imageName selectedimage:(NSString *)selectedImageName
{
    childVc.title = title;
    
    // 未选中时的图片颜色
    UIImage *unselectedImage = [UIImage imageNamed:imageName];
    unselectedImage = [unselectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.image = unselectedImage;
    
    // 选中时的图片颜色
    UIImage *selectedImage = [UIImage imageNamed:selectedImageName];
    selectedImage = [selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = selectedImage;
    
    // 字体大小，颜色（未被选中时）
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor blackColor], NSForegroundColorAttributeName, [UIFont fontWithName:@"Helvetica" size:12.0f], NSFontAttributeName, nil] forState:UIControlStateNormal];

    // 添加为tabbar控制器的子控制器
    NavigationViewController *nav = [[NavigationViewController alloc] initWithRootViewController:childVc];
    [nav.navigationBar setBackgroundImage:[UIImage imageNamed:@"nav"] forBarMetrics:UIBarMetricsDefault];
    [self addChildViewController:nav];
}


@end
